/**
 * texturedcube - a lab about webgl rotating cube, cross-domain textures 
 */

define('texturedcube', ['remote', 'gamelib'], function (remote, gamelib) {
    'use strict';
    
    remote.img('http://profile.ak.fbcdn.net/hprofile-ak-snc4/174524_897105369_1407940_n.jpg', function (img) {
        var texture = new gamelib.THREE.Texture(img),
            box;
        
        texture.needsUpdate = true;
        
        box = gamelib.createBox(0, 30, 40, 30, 30, 30, {map: texture, ambient:0x555555});
        box.angle = 0;
        box.update = function () {
            box.body.SetAngle(box.angle += 0.01);
            gamelib.Object.prototype.update.call(box);
        };
        
        // Create floor, this has no physical presents, just visual
        var material = new gamelib.THREE.MeshPhongMaterial({color:0xffffff});
        gamelib.scene.addObject(new gamelib.THREE.Mesh(new gamelib.THREE.CubeGeometry(10000, 1, 10000), material));
        
        gamelib.camera.position.set(0, 90, 150);
        gamelib.camera.lookAt(0, 60, 0);
        gamelib.camera.updateProjectionMatrix();
        gamelib.createDirectionalLight(-1, 1, 1, 0xffffff, 0.9);
        gamelib.createPointLight(20, 80, 80, 0xffffff, 0,9);
        gamelib.createAmbientLight(0x666666);
        gamelib.play();
    });
    
});